{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pysam"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "inbam='/home/xiaoyifu/rice.train.uncalled4.bam'\n",
    "#/home/xiaoyifu/rice.train.uncalled4.bam\n",
    "#/home/xiaoyifu/rice_japonica_r94.demo.train.bam\n",
    "bamfile = pysam.AlignmentFile(inbam)\n",
    "bam_index = pysam.IndexedReads(bamfile)\n",
    "bam_index.build()\n",
    "read_iter = bam_index.find('934384a5-fdfc-4ac4-8e58-7a0532f39c40')\n",
    "for bam_read in read_iter:\n",
    "    read_dict = dict(bam_read.tags)\n",
    "    mv_a = read_dict[\"mv\"]\n",
    "    seq_a=bam_read.query_sequence\n",
    "    ref_seq_a=bam_read.get_reference_sequence()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "\n",
    "inbam='/home/xiaoyifu/rice_japonica_r94.demo.train.bam'\n",
    "#/home/xiaoyifu/rice.train.uncalled4.bam\n",
    "#/home/xiaoyifu/rice_japonica_r94.demo.train.bam\n",
    "bamfile = pysam.AlignmentFile(inbam)\n",
    "bam_index = pysam.IndexedReads(bamfile)\n",
    "bam_index.build()\n",
    "read_iter = bam_index.find('934384a5-fdfc-4ac4-8e58-7a0532f39c40')\n",
    "for bam_read in read_iter:\n",
    "    read_dict = dict(bam_read.tags)\n",
    "    mv_b = read_dict[\"mv\"]\n",
    "    seq_b=bam_read.query_sequence\n",
    "    ref_seq_b=bam_read.get_reference_sequence()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "true\n",
      "true\n",
      "true\n"
     ]
    }
   ],
   "source": [
    "if mv_a==mv_b:\n",
    "    print('true')\n",
    "\n",
    "if seq_a==seq_b:\n",
    "    print('true')\n",
    "\n",
    "if ref_seq_a==ref_seq_b:\n",
    "    print('true')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "deepsignalpenv",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.17"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
